//
//  WJ_SportVC.m
//  ChatOnLine
//
//  Created by dllo on 16/8/10.
//  Copyright © 2016年 WWT. All rights reserved.
//

#import "WJ_SportVC.h"
#import "CustomAnimateTransitionPush.h"
#import "WJDataManager.h"
#import "WJ_StartSportVC.h"
#import "SportDetailVC.h"

#define kBaseColor [UIColor colorWithRed:90 / 255.0 green:177 / 255.0 blue:64 / 255.0 alpha:1]
#define MAS_SHORTHAND          //这样子 `mas_width` 等就可以写成 `width`
#define MAS_SHORTHAND_GLOBALS  //这样子 `mas_equalTo` 和 `equalTo` 就没有区别了

@interface WJ_SportVC ()<UINavigationControllerDelegate>

@property (nonatomic, strong) UILabel *kmLable;

@property (nonatomic, strong) UILabel *timeLable;

@property (nonatomic, strong) UILabel *countLable;

@end

@implementation WJ_SportVC

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    // 必须在viewDidAppear或者viewWillAppear中写，因为每次都需要将delegate设为当前界面
    self.navigationController.delegate=self;
    
    self.navigationController.navigationBarHidden = YES;

    NSArray *array = [[WJDataManager shareFMDB]totleDistance];
    
    self.kmLable.text = array[0];
    self.timeLable.text = array[1];
    self.countLable.text = array[2];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self config];
    
    [self createView];
}

- (void)config
{
    self.view.backgroundColor = kBaseColor;
    
    UILabel *lable = [[UILabel alloc]init];
    [self.view addSubview:lable];
    [lable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(34);
        make.left.mas_equalTo(100);
        make.right.mas_equalTo(-100);
        make.height.mas_equalTo(30);
    }];
    lable.textColor = [UIColor whiteColor];
    lable.textAlignment = 1;
    lable.text = @"运动";
    lable.font = [UIFont systemFontOfSize:20];
    
    UIButton *popButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:popButton];
    [popButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(24);
        make.left.mas_equalTo(20);
        make.size.mas_equalTo(CGSizeMake(50, 40));
    }];
    [popButton setImage:[UIImage imageNamed:@"Return"] forState:0];
    [popButton setImage:[UIImage imageNamed:@"ReturnClick"] forState:UIControlStateHighlighted];
    [popButton addTarget:self action:@selector(popAct) forControlEvents:1<<6];
    
    UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:detailButton];
    [detailButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(34);
        make.right.mas_equalTo(-20);
        make.size.mas_equalTo(CGSizeMake(100, 30));
    }];
    detailButton.titleLabel.textColor = [UIColor whiteColor];
    [detailButton setTitle:@"跑步详情" forState:0];
    [detailButton addTarget:self action:@selector(detailAct) forControlEvents:1<<6];
    
}
 // 左面返回上一页
- (void)popAct
{
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.barTintColor =  [UIColor colorWithRed:0.19f green:0.19f blue:0.21f alpha:1.00f];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)detailAct
{
    SportDetailVC *sportVc = [[SportDetailVC alloc]init];
    [self.navigationController pushViewController:sportVc animated:YES];
}

- (void)createView
{
    self.kmLable = [[UILabel alloc]init];
    [self.view addSubview:self.kmLable];
    [self.kmLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(64 + 0.07 * SCREEN_HEIGHT);
        make.left.mas_equalTo(0.136 * SCREEN_HEIGHT);
        make.right.mas_equalTo(- 0.136 * SCREEN_HEIGHT);
        make.height.mas_equalTo(100);
    }];
    self.kmLable.font = [UIFont fontWithName:@"Knockout-HTF67-FullBantamwt" size:120];
    self.kmLable.textAlignment = 1;
    self.kmLable.text = @"0.00";
    self.kmLable.textColor = [UIColor whiteColor];
    
    UILabel *lable = [[UILabel alloc]init];
    [self.view addSubview:lable];
    [lable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.kmLable).offset(100);
        make.left.mas_equalTo(0.136 * SCREEN_HEIGHT);
        make.right.mas_equalTo(- 0.136 * SCREEN_HEIGHT);
        make.height.mas_equalTo(40);
    }];
    lable.text = @"跑步总公里(公里)";
    lable.textAlignment = 1;
    lable.textColor = [UIColor whiteColor];
    
    
    self.timeLable = [[UILabel alloc]init];
    [self.view addSubview:self.timeLable];
    [self.timeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(204 +  0.136 * SCREEN_HEIGHT);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(- SCREEN_WIDTH / 2);
        make.height.mas_equalTo(50);
    }];
    self.timeLable.font = [UIFont fontWithName:@"Knockout-HTF67-FullBantamwt" size:50];
    self.timeLable.textAlignment = 1;
    self.timeLable.text = @"0.0";
    self.timeLable.textColor = [UIColor whiteColor];

    UILabel *secTime = [[UILabel alloc]init];
    [self.view addSubview:secTime];
    [secTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.timeLable).offset(50);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(- SCREEN_WIDTH / 2);
        make.height.mas_equalTo(30);
    }];
    secTime.text = @"累计用时(小时)";
    secTime.textAlignment = 1;
    secTime.textColor = [UIColor whiteColor];
    

    self.countLable = [[UILabel alloc]init];
    [self.view addSubview:self.countLable];
    [self.countLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(204 +  0.136 * SCREEN_HEIGHT);
        make.left.mas_equalTo(SCREEN_WIDTH / 2);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];
    self.countLable.font = [UIFont fontWithName:@"Knockout-HTF67-FullBantamwt" size:50];
    self.countLable.textAlignment = 1;
    self.countLable.text = @"0";
    self.countLable.textColor = [UIColor whiteColor];
    
    UILabel *countLab = [[UILabel alloc]init];
    [self.view addSubview:countLab];
    [countLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.countLable).offset(50);
        make.left.mas_equalTo(SCREEN_WIDTH / 2);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(30);
    }];
    countLab.text = @"运动次数";
    countLab.textAlignment = 1;
    countLab.textColor = [UIColor whiteColor];
    
    UIView *roundView = [[UIView alloc]init];
    [self.view addSubview:roundView];
    [roundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(SCREEN_WIDTH/2 - 50);
        make.bottom.mas_equalTo(- 0.136 * SCREEN_HEIGHT);
        make.size.mas_equalTo(CGSizeMake(100, 100));
    }];
    roundView.backgroundColor = [UIColor whiteColor];
    roundView.layer.cornerRadius = 50;
    roundView.layer.masksToBounds = YES;
    
    self.startButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:self.startButton];
    [self.startButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(roundView);
        make.size.mas_equalTo(CGSizeMake(90, 90));
    }];
    self.startButton.backgroundColor = kBaseColor;
    self.startButton.layer.cornerRadius = 45;
    [self.startButton setTitle:@"开始跑步" forState:0];
    [self.startButton addTarget:self action:@selector(pushAct:) forControlEvents:1<<6];
}

//用来自定义转场动画
-(id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
{
    
    if(operation==UINavigationControllerOperationPush)
    {
        CustomAnimateTransitionPush *animateTransitionPush=[CustomAnimateTransitionPush new];
        return animateTransitionPush;
    }
    else
    {
        return nil;
    }
    
}

- (void)pushAct:(UIButton *)button
{
    WJ_StartSportVC *startVC = [WJ_StartSportVC new];
    [self.navigationController pushViewController:startVC animated:YES];
    
}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
